#!/usr/bin/env python3
# coding:utf-8
import requests
import json
# server_url = 'http://0.0.0.0:8080/core/user/'
server_url = 'http://0.0.0.0:8090/core/user/'

def get_user_by_id():
    data = {'user_id': "6", }
    url = server_url + 'get_user_by_id/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())



def add_user():
    data = {'organization_id': 1, 'email': '282', 'job_number': '2133', 'phone_number': '313', 'quarter_id': 1,
     'description': 'ddd', 'roles_id': [1,2], 'password': '123', 'department_id': 1, 'safe_code': '2133',
     'username': 'zao3', 'status': 1, 'sex': 1}
    url = server_url + 'add_user/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())


def edit_user():
    data = {'id': "5", 'username':'cui1', 'email':12383, 'phone_number':882,
            'safe_code':'abc3', 'sex':1, 'department_id':2, 'organization_id':1}
    url = server_url + 'edit_user/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())

def delete_user_by_id_interface():
    data = {'id': 5, }
    url = server_url + 'delete_user_by_id/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())


def get_users_by_department_id_interface():
    data = {'id': 1, }
    url = server_url + 'get_users_by_department_id/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())


def get_user_by_organization_id_interface():
    data = {'id': 1}
    url = server_url + 'get_users_by_organization_id/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())

def add_role():
    data = {'name': 'test1', 'code': 123, 'description': '描述'}
    url = server_url + 'add_role/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())

def edit_role_interface():
    data = {'id': 3, 'name': 'test2', 'code': 1234, 'description': '描述'}
    url = server_url + 'edit_role/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())

def delete_role_interface():
    data = {'id': 3}
    url = server_url + 'delete_role/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())

def add_roles_to_user_interface():
    data = {'user_id': 57, 'roles': [4, 5]}
    url = server_url + 'add_roles_to_user/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())

def add_users_to_role():
    data = {'role_id': 5, 'users': [58,59]}
    url = server_url + 'add_users_to_role/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())

def delete_role_with_user_interface():
    data = {'user_id': 6, 'role_id': 4}
    url = server_url + 'delete_role_from_user/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())

def add_buttons_to_role_interface():
    data = {'buttons': [1, 2], 'role_id': 4}
    url = server_url + 'add_buttons_to_role/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())


def change_password_interface():
    data = {'user_id': 57, 'old_password': '123',
            'new_password':'12345', 'repassword': '12345'}
    url = server_url + 'change_password/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())

def get_u():
    data = {'u_id': 59}
    url = server_url + 'get_u/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())


def disable_user():
    data = {'id': 68 }
    url = server_url + 'disable_user/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())

def reset_password():
    data = {'id': 68 }
    url = server_url + 'reset_password/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())

def login():
    data = {'username': '123123驱蚊器二2', 'password': '123456'}
    url = server_url + 'login/'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())



login()
# add_user()
# get_user_by_id()
# edit_user()
# delete_user_by_id_interface()
# get_users_by_department_id_interface()
# get_user_by_organization_id_interface()
# add_role()
# edit_role_interface()
# delete_role_interface()
# get_children_by_module_id()
# delete_role_interface()
# add_roles_to_user_interface()
# add_users_to_role()
# delete_role_with_user_interface()
# add_buttons_to_role_interface()
# change_password_interface()
# get_u()
# disable_user()
# reset_password()


if __name__ == '__main__':
    pass

